package chapter7.test.no3;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("Input the class name of the method you want to execute");
        String name;
        A a=null;
        while (true){
            name = scanner.next();
            if (name.equals("A")) {
                a = new A();
            } else if (name.equals("B")) {
                a = new B();
            } else if (name.equals("C")) {
                a = new C();
            } else {
                System.out.printf("No class found named %s\n", name);
                break;
            }
            System.out.println("Construction complete");
            a.f();
        }
    }
}
class A{
    int i;
    int f(){
        System.out.println("f-A");
        this.i=1;
        return 0;
    }
    A(){
        f();
        System.out.println(this.i);
    }
}
class B extends A {
    int i;
    @Override
    int f() {
        System.out.println("f-B");
        return 0;
    }
    B(){
        super();
        super.f();
        System.out.println("B");
        f();
    }
}
class C extends A {
    int i;
    @Override
    int f() {
        System.out.println("f-C");
        return 0;
    }
    C(){
        super();
        super.f();
        System.out.println("C");
        f();
    }
}